package com.cincc.cincc_pbx.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;

import com.cincc.cincc_pbx.R;
import com.gyf.immersionbar.ImmersionBar;

public class ContactFragment extends Fragment implements View.OnClickListener {
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_contact, container, false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        TextView titleText = view.findViewById(R.id.user_name_tv);
        int statusBarHeight = ImmersionBar.getStatusBarHeight(this);
        ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) titleText.getLayoutParams();
        lp.topMargin = statusBarHeight + 10;
        titleText.setLayoutParams(lp);

        RelativeLayout internal = view.findViewById(R.id.internal_relayout);
        RelativeLayout myExternal = view.findViewById(R.id.my_external_relayout);
        RelativeLayout vccExternal = view.findViewById(R.id.vcc_external_relayout);
        internal.setOnClickListener(this);
        myExternal.setOnClickListener(this);
        vccExternal.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.internal_relayout) {
            openInternal();
        } else if (v.getId() == R.id.my_external_relayout) {
            openExternal(1);
        } else if (v.getId() == R.id.vcc_external_relayout) {
            openExternal(0);
        }
    }

    private void openInternal() {
        Intent i = new Intent(getActivity(), InternalActivity.class);
        startActivity(i);
    }

    private void openExternal(int type) {
        Intent i = new Intent(getActivity(), ExternalActivity.class);
        i.putExtra("type", type);
        startActivity(i);
    }
}
